const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')

module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    clean: true,
  },
  plugins: [
    new HtmlWebpackPlugin(),
    // 使用 webpack 内置的插件来预置全局变量
    new webpack.ProvidePlugin({
      _: 'lodash'
    })
  ],
  module: {
    rules: [{
      test: require.resolve('./src/index.js'),
      use: 'imports-loader?wrapper=window'
    }, {
      test: require.resolve('./src/global.js'),
      // 以下相当于 module.exports = { file, parse: helpers.parse }
      use: 'exports-loader?type=commonjs&exports=file,multiple|helpers.parse|parse'
    }]
  }
}